<template>
  <div class="visitor-alreadyVisited">
    <div class="search-group">
      <div class="input-wrap">
        <div class="label">街路巷(小区):</div>
        <div class="input-item">
          <a-select
            v-model="queryParam.xQfDzbm"
            placeholder="请选择"
            show-search
            allowClear
            :filterOption="filterOption"
            @change="(value) => handleSelectChange(value, 1)"
          >
            <a-select-option v-for="(item, index) in villageList" :key="index" :value="item.fDzbm">
              {{ item.fName }}
            </a-select-option>
          </a-select>
        </div>
      </div>
      <div class="input-wrap">
        <div class="label">建筑物:</div>
        <div class="input-item">
          <a-select
            allowClear
            v-model="queryParam.jzfDzbm"
            placeholder="请选择"
            @change="(value) => handleSelectChange(value, 2)"
          >
            <a-select-option v-for="(item, index) in buildingList" :key="index" :value="item.fDzbm">
              {{ item.fName }}
            </a-select-option>
          </a-select>
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">地址类型:</div>
        <div class="input-item">
          <a-select allowClear ref="select" v-model="queryParam.fDzlx" placeholder="请选择">
            <a-select-option v-for="(item, index) in buildTypeList" :key="index" :value="item.value">
              {{ item.text }}
            </a-select-option>
          </a-select>
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">建筑物类型:</div>
        <div class="input-item">
          <a-select allowClear ref="select" v-model="queryParam.fJzwlx" placeholder="请选择">
            <a-select-option v-for="(item, index) in buildCategoryList" :key="index" :value="item.value">
              {{ item.text }}
            </a-select-option>
          </a-select>
        </div>
      </div>

      <div class="btn-wrap">
        <a-button class="searchBtn" @click="searchQuery(queryParam.startTime, queryParam.endTime)" type="primary">
          搜索
        </a-button>
        <a-button class="resetBtn" @click="searchReset()" type="primary"> 重置 </a-button>
      </div>
    </div>

    <div>
      <a-table
        ref="table"
        rowKey="id"
        class="tableList"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
      </a-table>
    </div>
  </div>
</template>

<script>
import startEndTime from '@/components/startEndTime'
import { JeecgListMixinNew } from '@/mixins/JeecgListMixinNew'
import { getSubordinateList } from '../../../api/api'
import { handleSelectChange } from '../../../utils/util'
export default {
  name: 'build',
  components: { startEndTime },
  mixins: [JeecgListMixinNew],
  props: {
    idCode: {
      type: String,
      default: '',
    },
    villageList: {
      type: Array,
      default: () => [],
    },
  },
  watch: {
    idCode(newVal) {
      this.extendParams.idCode = newVal
    },
  },
  data() {
    return {
      url: {
        list: '/indeed/area/buildingAreaList',
      },
      publicVisible: false,
      disableMixinCreated: true,
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 100,
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '街路巷(小区)',
          dataIndex: 'fJlxxqmc',
          ellipsis: true,
          width: 300,
          align: 'center',
        },
        {
          title: '建筑物',
          dataIndex: 'fJzwmc',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '地址类型 ',
          dataIndex: 'fDzlx',
          ellipsis: true,
          align: 'center',
          customRender: function (t, r, index) {
            return t == 0 ? '城镇' : '农村'
          },
        },
        {
          title: '建筑物类型',
          dataIndex: 'fJzwlx',
          ellipsis: true,
          customRender: function (t, r, index) {
            let mapText = {
              0: '居民住宅楼',
              1: '平房',
              3: '商业楼',
              6: '商铺住宅连体',
            }
            return mapText[t] ? mapText[t] : ''
          },
          align: 'center',
        },
        {
          title: '采集时间',
          dataIndex: 'createTime',
          ellipsis: true,
          align: 'center',
          width: 200,
        },
      ],
      project_company_type: [],
      times: {},
      buildingList: [],
      queryParam: this.initQueryParams(),
      buildTypeList: [
        {
          text: '城镇',
          value: 0,
        },
        {
          text: '农村',
          value: 1,
        },
      ],
      buildCategoryList: [
        {
          text: '居民住宅楼',
          value: 0,
        },
        {
          text: '平房',
          value: 1,
        },
        {
          text: '商业楼',
          value: 3,
        },
        {
          text: '商铺住宅连体',
          value: 6,
        },
      ],
    }
  },
  methods: {
    initQueryParams() {
      return {
        xQfDzbm: undefined,
        jzfDzbm: undefined,
        fDzlx: undefined,
        fJzwlx: undefined,
      }
    },
    searchReset() {
      if (!this.idCode) {
        this.$message.error('请选择机关信息!')
        return
      }
      this.queryParam = this.initQueryParams()
      this.buildingList = []
      this.loadData(1)
    },
    handleSelectChange,
    filterOption(input, option) {
      const inputText = input ? input.trim().toLowerCase() : input
      return option.componentOptions.children[0].text.toLowerCase().indexOf(inputText) >= 0
    },
    searchQuery() {
      if (!this.idCode) {
        this.$message.error('请选择机构信息!')
        return
      }
      const { startTime, endTime } = this.queryParam
      if ((startTime && !endTime) || (!startTime && endTime)) {
        this.$message.error('开始时间结束时间必须同时选择')
        return
      }
      this.loadData(1)
    },
    timeChange(v, index) {
      if (index == 1) {
        this.queryParam.startTime = this.$moment(v).valueOf()
        if (v == null) {
          this.queryParam.startTime = null
        }
      } else {
        this.queryParam.endTime = this.$moment(v).valueOf()
        if (v == null) {
          this.queryParam.endTime = null
        }
      }
    },
  },
}
</script>
